﻿#region References
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion

namespace Ness.Engine.GUI
{
    /// <summary>
    /// Allows debugging output to either the in-game console or command line
    /// </summary>
    static class Debugger
    {
        #region Public variables
        static public string outputted;
        static public string type;
        #endregion

        /// <summary>
        /// Initialises the debugging class
        /// </summary>
        /// <param name="typ">"cmd" for Command Line output, "game" for Game UI output</param>
        static public void OutputTo(string typ)
        {
            type = typ;
            Debugger.WriteLine("Debug output to: " + type);
        }

        /// <summary>
        /// Writes to the debugging application
        /// </summary>
        /// <param name="line">The string to write</param>
        static public void WriteLine(object line)
        {
            if (type == "cmd")
            {
                Console.WriteLine(AddToOutput(line.ToString()));
            }
            else
            {
                //ADD GAME WINDOW CODE HERE
            }
        }

        /// <summary>
        /// Writes to the debugging application with error text
        /// </summary>
        /// <param name="line">The string to write</param>
        static public void WriteError(object line)
        {
            if (type == "cmd")
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(AddToOutput("Error: " + line.ToString()));
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
                //ADD GAME WINDOW CODE HERE
            }
        }

        /// <summary>
        /// Writes to the debugging application with a certain colour
        /// </summary>
        /// <param name="line">The string to write</param>
        static public void WriteColour(object line, ConsoleColor colour)
        {
            if (type == "cmd")
            {
                Console.ForegroundColor = colour;
                Console.WriteLine(AddToOutput(line.ToString()));
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
                //ADD GAME WINDOW CODE HERE
            }
        }

        /// <summary>
        /// Writes to the debugging application with Lua output
        /// </summary>
        /// <param name="line">The string to write</param>
        static public void WriteLua(object line)
        {
            if (type == "cmd")
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(AddToOutput(line.ToString()));
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
                //ADD GAME WINDOW CODE HERE
            }
        }

        static public string AddToOutput(string line)
        {
            outputted += "\n" + line;

            return line;
        }
    }
}
